package cn.jtfadmin.core.modules.sys.utils;


import cn.jtfadmin.base.lang.common.security.UserDetails;
import cn.jtfadmin.core.config.shiro.UserDetailsPropertiesKey;
import cn.jtfadmin.core.modules.sys.domain.dto.SysUserModelDTO;
import cn.jtfadmin.core.modules.sys.domain.dto.UserMenuRDTO;

import java.util.Objects;
import java.util.Set;


public class SysUserDetailUtil {


    public static UserMenuRDTO getUserMenu(UserDetails userDetails) {
        if(Objects.isNull(userDetails)){
            return null;
        }
        UserDetails userDetailByType = userDetails.getUserDetailByType(UserDetailsPropertiesKey.TYPE);
        if(!Objects.isNull(userDetailByType)){
            return (UserMenuRDTO) userDetailByType.getProperties().get(UserDetailsPropertiesKey.MENU_PERMISSION_TYPE);
        }
        return null;
    }

    public static SysUserModelDTO getUserModelDTO(UserDetails userDetails){
        if(Objects.isNull(userDetails)){
            return null;
        }
        UserDetails userDetailByType = userDetails.getUserDetailByType(UserDetailsPropertiesKey.TYPE);
        if(!Objects.isNull(userDetailByType)){
            return (SysUserModelDTO) userDetailByType.getProperties().get(UserDetailsPropertiesKey.USER_MODEL_TYPE);
        }
        return null;
    }

    public static Set<String> getManagerDepIds(UserDetails userDetails) {
        if(Objects.isNull(userDetails)){
            return null;
        }
        UserDetails userDetailByType = userDetails.getUserDetailByType(UserDetailsPropertiesKey.TYPE);
        if(!Objects.isNull(userDetailByType)){
            return (Set<String>) userDetailByType.getProperties().get(UserDetailsPropertiesKey.USER_MANAGER_DEP_IDS_TYPE);
        }
        return null;
    }


    public static Set<String> getPermissionDataRule(UserDetails userDetails) {
        if(Objects.isNull(userDetails)){
            return null;
        }
        UserDetails userDetailByType = userDetails.getUserDetailByType(UserDetailsPropertiesKey.TYPE);
        if(!Objects.isNull(userDetailByType)){
            return (Set<String>) userDetailByType.getProperties().get(UserDetailsPropertiesKey.USER_PERMISSION_DATA_RULE_TYPE);
        }
        return null;
    }
}
